package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class OrderContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class OrderContainer  //The class which creates the order-list
{
    // instance variables - replace the example below with your own
    private ArrayList<Order> orderList;
    private static OrderContainer instance;

    /**
     * Constructor for objects of class OrderContainer
     */
    private OrderContainer()
    {
        orderList = new ArrayList<Order>();
    }
    
    public static OrderContainer getInstance() //we make use of singleton. In that way, we only get to make one list.
    {
        if(instance == null)
        {
            instance = new OrderContainer();            
        }
                
        return instance;
    }
    
    public void addOrder(Order newOrder)  // adds an order to the list
    {
        orderList.add(newOrder);
    }
    
    public Order findOrder(int orderId) //finds an order in the list
    {
        int index = 0;
        boolean found = false;
        while(!found && index < orderList.size())
        {
            String stringId = ""+orderId;
            if(orderList.get(index).getOrderId().equals(stringId))
            {
                found = true;
                
            }
            else
            {
                index++;
            }
            
            if(!found)
            {
                System.out.println("Order not found");
                
            }                      
        }
        return orderList.get(index);
    }
}
